#include "filepool.h"
#include <QString>
#include "globals.h"



FilePool::FilePool()
{
    const QString k_path = "/usr/share/hydrogen/data/drumkits/GMkit/";

    open(k_path+"stick_Woody.flac");
    open(k_path+"clap_Dry_c.flac");
    open(k_path+"misc_Cowbell.flac");
}

FilePool::~FilePool(){foreach(SNDFILE * id, files) close(id);}

SNDFILE * FilePool::open(const QString & name)
{
    SF_INFO sfinfo;
    SNDFILE * sndFile;
    if( !(sndFile =
          sf_open(name.toAscii().data(), SFM_READ, &sfinfo)))
            gl::log("can not open sound file");
    else files.append(sndFile);
    return sndFile;
}

void FilePool::close(SNDFILE * id){
    files.removeAll(id);
    sf_close(id);
}
